using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;

using ILRuntime.CLR.TypeSystem;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.Runtime.Stack;
using ILRuntime.Reflection;
using ILRuntime.CLR.Utils;
using System.Linq;

namespace ILRuntime.Runtime.Generated
{
    unsafe class huqiang_Communication_KcpManager_Binding
    {
        public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
        {
            BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
            MethodBase method;
            FieldInfo field;
            Type[] args;
            Type type = typeof(huqiang.Communication.KcpManager);
            args = new Type[]{};
            method = type.GetMethod("get_server", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, get_server_0);
            args = new Type[]{typeof(System.Func<huqiang.Communication.KcpLink>)};
            method = type.GetMethod("SetClientFactory", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, SetClientFactory_1);
            args = new Type[]{};
            method = type.GetMethod("Dispose", flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, Dispose_2);

            field = type.GetField("Port", flag);
            app.RegisterCLRFieldGetter(field, get_Port_0);
            app.RegisterCLRFieldSetter(field, set_Port_0);
            app.RegisterCLRFieldBinding(field, CopyToStack_Port_0, AssignFromStack_Port_0);
            field = type.GetField("UserBufferCount", flag);
            app.RegisterCLRFieldGetter(field, get_UserBufferCount_1);
            app.RegisterCLRFieldSetter(field, set_UserBufferCount_1);
            app.RegisterCLRFieldBinding(field, CopyToStack_UserBufferCount_1, AssignFromStack_UserBufferCount_1);


            app.RegisterCLRCreateDefaultInstance(type, () => new huqiang.Communication.KcpManager());
            app.RegisterCLRCreateArrayInstance(type, s => new huqiang.Communication.KcpManager[s]);

            args = new Type[]{};
            method = type.GetConstructor(flag, null, args, null);
            app.RegisterCLRMethodRedirection(method, Ctor_0);

        }


        static StackObject* get_server_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            huqiang.Communication.KcpManager instance_of_this_method = (huqiang.Communication.KcpManager)typeof(huqiang.Communication.KcpManager).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)0);
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.server;

            object obj_result_of_this_method = result_of_this_method;
            if(obj_result_of_this_method is CrossBindingAdaptorType)
            {    
                return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance);
            }
            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
        }

        static StackObject* SetClientFactory_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Func<huqiang.Communication.KcpLink> @func = (System.Func<huqiang.Communication.KcpLink>)typeof(System.Func<huqiang.Communication.KcpLink>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)8);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            huqiang.Communication.KcpManager instance_of_this_method = (huqiang.Communication.KcpManager)typeof(huqiang.Communication.KcpManager).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.SetClientFactory(@func);

            return __ret;
        }

        static StackObject* Dispose_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            huqiang.Communication.KcpManager instance_of_this_method = (huqiang.Communication.KcpManager)typeof(huqiang.Communication.KcpManager).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Dispose();

            return __ret;
        }


        static object get_Port_0(ref object o)
        {
            return ((huqiang.Communication.KcpManager)o).Port;
        }

        static StackObject* CopyToStack_Port_0(ref object o, ILIntepreter __intp, StackObject* __ret, IList<object> __mStack)
        {
            var result_of_this_method = ((huqiang.Communication.KcpManager)o).Port;
            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value = result_of_this_method;
            return __ret + 1;
        }

        static void set_Port_0(ref object o, object v)
        {
            ((huqiang.Communication.KcpManager)o).Port = (System.Int32)v;
        }

        static StackObject* AssignFromStack_Port_0(ref object o, ILIntepreter __intp, StackObject* ptr_of_this_method, IList<object> __mStack)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            System.Int32 @Port = ptr_of_this_method->Value;
            ((huqiang.Communication.KcpManager)o).Port = @Port;
            return ptr_of_this_method;
        }

        static object get_UserBufferCount_1(ref object o)
        {
            return ((huqiang.Communication.KcpManager)o).UserBufferCount;
        }

        static StackObject* CopyToStack_UserBufferCount_1(ref object o, ILIntepreter __intp, StackObject* __ret, IList<object> __mStack)
        {
            var result_of_this_method = ((huqiang.Communication.KcpManager)o).UserBufferCount;
            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value = result_of_this_method;
            return __ret + 1;
        }

        static void set_UserBufferCount_1(ref object o, object v)
        {
            ((huqiang.Communication.KcpManager)o).UserBufferCount = (System.Int32)v;
        }

        static StackObject* AssignFromStack_UserBufferCount_1(ref object o, ILIntepreter __intp, StackObject* ptr_of_this_method, IList<object> __mStack)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            System.Int32 @UserBufferCount = ptr_of_this_method->Value;
            ((huqiang.Communication.KcpManager)o).UserBufferCount = @UserBufferCount;
            return ptr_of_this_method;
        }



        static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* __ret = ILIntepreter.Minus(__esp, 0);

            var result_of_this_method = new huqiang.Communication.KcpManager();

            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
        }


    }
}
